/**══════════════════════════════════╗
*作    者：songbaobao                                                  ║
*职    业：我以我血荐轩辕                                              ║
*CSND地址：https://blog.csdn.net/weixin_43949535                       ║
**GitHub ：https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
**GitEE  ：https://gitee.com/lucky912_admin/code-up_-pat               ║
*═══════════════════════════════════╣
*创建时间：                                                           
*功能描述：                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*结束时间:                                                           
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              西南\./联大               \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/
#include <iostream>
#include <vector>
#include <string.h>
#include <unordered_map>
#include <ctype.h>
#include <queue>
#include <list>
#include <map>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;

#if 1
bool myLeap(int year)
{
	return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
#endif

#if B
//基姆拉尔森公式
int calc_week(int y, int m, int d) 
{
	if (m == 1 || m == 2) { //month  13,14,3,...12
		y--;
		m += 12;
	}
	int tag = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
	return tag;
}
#endif


int main()
{
#if A
	int year1, year2;
	char year1Str[9] = { 0 }, year2Str[9] = { 0 };
	int yearArr[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
	while (EOF != scanf("%s%s", year1Str, year2Str))
	{
		int y1 = 0, y2 = 0, m1 = 0, m2 = 0, d1 = 0, d2 = 0, result = 1;
		char* str1, * str2;

		char ystr[5] = { 0 }, mstr[3] = { 0 }, dstr[3] = { 0 };
		year1 = atoi(year1Str);
		year2 = atoi(year2Str);
		if (year1 > year2)
		{
			str1 = year2Str;
			str2 = year1Str;
		}
		else
		{
			str1 = year1Str;
			str2 = year2Str;
		}
		
		strncpy(ystr, str1, 4 * sizeof(char));
		strncpy(mstr, str1 + 4, 2 * sizeof(char));
		strncpy(dstr, str1 + 6, 2 * sizeof(char));
		y1 = atoi(ystr);
		m1 = atoi(mstr);
		d1 = atoi(dstr);

		strncpy(ystr, str2, 4 * sizeof(char));
		strncpy(mstr, str2 + 4, 2 * sizeof(char));
		strncpy(dstr, str2 + 6, 2 * sizeof(char));
		y2 = atoi(ystr);
		m2 = atoi(mstr);
		d2 = atoi(dstr);

		while (y1 < y2 || m1 < m2 || d1 < d2)
		{
			if (myLeap(y1))
			{
				yearArr[1] = 29;
			}
			else
			{
				yearArr[1] = 28;
			}

			d1++;
			if (yearArr[m1 - 1] + 1 == d1)
			{
				m1++;
				d1 = 1;
			}

			if (m1 == 13)
			{
				y1++;
				m1 = 1;
			}

			result++;
		}
		printf("%d\n", result);		
	}
#endif
	
#if B
	int day, year, month;
	char name[10] = { 0 };
	const char* MonArr[12] = { "January","February","March","April",
							   "May","June","July","August",
							   "September","October","November","December" };
	const char* WeeArr[7] = { "Monday","Tuesday","Wednesday","Thursday",
							  "Friday","Saturday","Sunday" };

	while (EOF != scanf("%d%s%d", &day, name, &year))
	{
		int result;
		for (int i = 0; i < 12; ++i)
		{
			if (strcmp(name, MonArr[i]) == 0)
			{
				month = i + 1;
				break;
			}
		}
		result = calc_week(year, month, day);
		printf("%s\n", WeeArr[result]);
	}
#endif

#if C
	int m, n;
	
	while (~scanf("%d%d", &m, &n))
	{
		int monthArr[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
		int yearArr[12] = { 31,59,90,120,151,181,212,243,273,304,334,365 };
		if (myLeap(m))
		{
			monthArr[1] = 29;
			for (int i = 1; i < 12; ++i)
				yearArr[i]++;
		}
		for (int i = 0, j = n; ;++i)
		{
			if (j - monthArr[i] > 0)
			{
				j -= monthArr[i];
			}
			else
			{
				printf("%04d-%02d-%02d\n", m, i + 1, j);
				break;
			}
		}
	
	}
#endif

#if D
	int m;
	scanf("%d", &m);
	while (m--)
	{
		// 测试数据已不存在闰年
		int year, month, day;
		bool flag = false;
		int monthArr[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
		scanf("%d%d%d", &year, &month, &day);

		if (day == monthArr[month - 1])
		{
			flag = true;
			day = 1;
			month++;
		}
		if (month == 13)
		{
			year++;
			month = 1;
		}
		if (flag)
			printf("%04d-%02d-%02d\n", year, month, day);
		else
			printf("%04d-%02d-%02d\n", year, month, day + 1);
	}
#endif

	int m;
	scanf("%d", &m);

	while (m--)
	{
		int year, month, day, sum;
		bool flag = false;
		int monthArr[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
		scanf("%d%d%d%d", &year, &month, &day, &sum);
		
		while (sum > 0)
		{
			if (month == 13)
			{
				year++;
				month = 1;
			}
			if (myLeap(year))
			{
				monthArr[1] = 29;
			}
			else
			{
				monthArr[1] = 28;
			}

			for (int i = month; i < 13; ++i)
			{
				if (day + sum > monthArr[month - 1])
				{
					sum -= (monthArr[month - 1] - day);
					sum--;
					month++;
					day = 1;
				}
				else
				{
					day += sum;
					sum = 0;
					break;
				}
			}
		}
		printf("%04d-%02d-%02d\n", year, month, day);

	}
	return 0;
}
/**
*备用注释：
*
*
*
*/
